import 'dart:io';
import 'package:path_provider/path_provider.dart';

/// 文件工具类，提供基本的文件操作功能
class FileUtil {
  /// 获取应用文档目录
  static Future<String> getDocumentsPath() async {
    final directory = await getApplicationDocumentsDirectory();
    return directory.path;
  }

  /// 获取临时目录
  static Future<String> getTemporaryPath() async {
    final directory = await getTemporaryDirectory();
    return directory.path;
  }

  /// 创建文件
  static Future<File> createFile(String path, String content) async {
    final file = File(path);
    return file.writeAsString(content);
  }

  /// 读取文件内容
  static Future<String> readFile(String path) async {
    try {
      final file = File(path);
      return await file.readAsString();
    } catch (e) {
      return "";
    }
  }

  /// 检查文件是否存在
  static Future<bool> fileExists(String path) async {
    final file = File(path);
    return file.exists();
  }

  /// 获取固定路径
  static Future<String> getFixedPath(String filename) async {
    final docsPath = await getDocumentsPath();
    final directory = Directory('$docsPath/examsys');
    if (!await directory.exists()) {
      await directory.create(recursive: true);
    }
    return '${directory.path}/$filename';
  }
} 